package com.chazz.service.impl;

import com.chazz.Do.GoodsDetailsInfo;
import com.chazz.Do.KeyValue;
import com.chazz.dao.impl.DiscountDaoImpl;
import com.chazz.dao.impl.PriceDaoImpl;
import com.chazz.dao.impl.SkuDaoImpl;
import com.chazz.entity.Brand;
import com.chazz.entity.Discount;
import com.chazz.entity.Goods;
import com.chazz.entity.Sku;
import com.chazz.service.GoodsInfoService;
import java.text.DecimalFormat;
import java.util.List;
import java.util.Map;

/**
 * 描述:商品详情拼接service
 *
 * @author Chazz
 * @create 2020-09-25 9:35
 */
public class GoodsInfoServiceImpl implements GoodsInfoService {

    /**
     * description: sutureCommodityInformation 通过查询多个表的数据，将一个完整的商品信息包装完成 <br>
     * version: 1.0 <br>
     * date: 2020/9/25 9:51 <br>
     * author: Chazz <br>
     * @param goodsId 商品id
     * @return com.chazz.Do.GoodsDetailsInfo 商品详情信息数据集
     */
    @Override
    public GoodsDetailsInfo sutureCommodityInformation(Integer goodsId) {
        Goods goods = new SkuDaoImpl().selectGoods(goodsId);
        Sku sku = new SkuDaoImpl().selectSku(goodsId);
        Brand brand = new SkuDaoImpl().seclectBrand(goods.getBrandid());
        List<KeyValue> attributes = new SkuDaoImpl().attributes(goods.getCategoryid());
        Discount discount = new SkuDaoImpl().selectDiscount(goods.getCategoryid());
        Double beforPrice = new PriceDaoImpl().selectPrice(goods.getGoodsid());
        Double afterPrice = discount.getType()*beforPrice;
        Double type = discount.getType();
        Double discountPrice = 1- type;
        DecimalFormat df = new DecimalFormat("#.00");
        Double s = Double.valueOf(df.format(discountPrice));
        discount.setType(s);
        String totalPriceStr = df.format(afterPrice);
        System.out.println(afterPrice);
        GoodsDetailsInfo goodsDetailsInfo = new GoodsDetailsInfo(goods, brand, sku, attributes,discount,beforPrice,totalPriceStr);
        return goodsDetailsInfo;
    }
}
